#include <assert.h>
#include <limits.h>
#include <stdio.h>
#include <string.h>

#include "lj_ringbuffer.h"
#include "lj_ringbuffer_print.h"
#include "ljdef.h"

#define DATA_AMOUNT 10

int main(int argc, char** argv)
{
    printf("hello world!\n");

    size_t ret;
    BUFFER_TYPE data[DATA_AMOUNT + 2] = { 0 };

    BUFFER_TYPE push[] = {
        { 1, "0123456" },
        { 2, "234567" },
        { 3, "345678" }
    };
    BUFFER_TYPE push_b[] = {
        { 4, "123456" },
        { 5, "234567" },
        { 6, "345678" },
        { 7, "456789" }
    };

    size_t length = sizeof(push) / sizeof(BUFFER_TYPE);
    print_buffer(push, length, "push");

    BUFFER_TYPE pull[4] = { 0 };

    lj_ringbuffer_t ring;

    lj_ring_buffer_init(&ring, data + 1, DATA_AMOUNT);
    print_ringbuffer(ring);

    ret = lj_ring_buffer_push(&ring, push, length);
    printf("push %zu\n", ret);
    assert(ret);
    ret = lj_ring_buffer_push(&ring, push, length);
    printf("push %zu\n", ret);
    assert(ret);
    ret = lj_ring_buffer_push(&ring, push, length);
    printf("push %zu\n", ret);
    assert(ret);
    print_ringbuffer(ring);

    ret = lj_ring_buffer_pull(&ring, pull, 3);
    printf("pull %zu\n", ret);
    assert(ret);
    print_buffer(pull, length, "pull");
    print_ringbuffer(ring);

    ret = lj_ring_buffer_push(&ring, push_b, 4);
    printf("push %zu\n", ret);
    print_ringbuffer(ring);
    assert(ret);

    print_buffer(data, DATA_AMOUNT + 2, "data");

    return 0;
}
